home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / swblocks / lockmain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-07  |  8.1 KB  |  234 lines

  1. VERSION 5.00
  2. Begin VB.Form LockForm 
  3.    AutoRedraw      =   -1  'True
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "SWBLogicalLocks Sample Application"
  6.    ClientHeight    =   4590
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   6675
  10.    ControlBox      =   0   'False
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4590
  15.    ScaleWidth      =   6675
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.Frame Frame2 
  18.       Caption         =   "Logical Locks Held By This Station"
  19.       Height          =   3075
  20.       Left            =   135
  21.       TabIndex        =   8
  22.       Top             =   1395
  23.       Width           =   6405
  24.       Begin VB.ListBox LockList 
  25.          Height          =   1815
  26.          Left            =   135
  27.          TabIndex        =   10
  28.          Top             =   675
  29.          Width           =   6090
  30.       End
  31.       Begin VB.CommandButton RefreshBtn 
  32.          Caption         =   "R&efresh"
  33.          Height          =   330
  34.          Left            =   3825
  35.          TabIndex        =   4
  36.          Top             =   2625
  37.          Width           =   1125
  38.       End
  39.       Begin VB.CommandButton UnlockBtn 
  40.          Caption         =   "&Release"
  41.          Height          =   330
  42.          Left            =   5130
  43.          TabIndex        =   5
  44.          Top             =   2625
  45.          Width           =   1125
  46.       End
  47.       Begin VB.Label Label2 
  48.          BorderStyle     =   1  'Fixed Single
  49.          Caption         =   " Handle                     Name                                       Owner                     Type"
  50.          Height          =   285
  51.          Left            =   135
  52.          TabIndex        =   11
  53.          Top             =   360
  54.          Width           =   6090
  55.       End
  56.    End
  57.    Begin VB.CommandButton CloseBtn 
  58.       Cancel          =   -1  'True
  59.       Caption         =   "&Close"
  60.       Height          =   375
  61.       Left            =   5310
  62.       TabIndex        =   6
  63.       Top             =   225
  64.       Width           =   1215
  65.    End
  66.    Begin VB.Frame Frame1 
  67.       Caption         =   "Acquire Lock"
  68.       Height          =   1095
  69.       Left            =   135
  70.       TabIndex        =   7
  71.       Top             =   135
  72.       Width           =   5010
  73.       Begin VB.CommandButton LockBtn 
  74.          Caption         =   "&Acquire"
  75.          Default         =   -1  'True
  76.          Height          =   330
  77.          Left            =   3700
  78.          TabIndex        =   3
  79.          Top             =   675
  80.          Width           =   1125
  81.       End
  82.       Begin VB.TextBox LockName 
  83.          Height          =   315
  84.          Left            =   675
  85.          MaxLength       =   64
  86.          TabIndex        =   0
  87.          Top             =   315
  88.          Width           =   4155
  89.       End
  90.       Begin VB.OptionButton LockType 
  91.          Caption         =   "Shareable"
  92.          Height          =   195
  93.          Index           =   1
  94.          Left            =   1890
  95.          TabIndex        =   2
  96.          Top             =   765
  97.          Width           =   1230
  98.       End
  99.       Begin VB.OptionButton LockType 
  100.          Caption         =   "Exclusive"
  101.          Height          =   195
  102.          Index           =   0
  103.          Left            =   675
  104.          TabIndex        =   1
  105.          Top             =   765
  106.          Value           =   -1  'True
  107.          Width           =   1230
  108.       End
  109.       Begin VB.Label Label1 
  110.          AutoSize        =   -1  'True
  111.          Caption         =   "Name"
  112.          Height          =   195
  113.          Left            =   135
  114.          TabIndex        =   9
  115.          Top             =   360
  116.          Width           =   420
  117.       End
  118.    End
  119. Attribute VB_Name = "LockForm"
  120. Attribute VB_GlobalNameSpace = False
  121. Attribute VB_Creatable = False
  122. Attribute VB_PredeclaredId = True
  123. Attribute VB_Exposed = False
  124. '============================================================
  125. ' SWBLogicalLocks Sample Application.
  126. ' This program contains the code necessary
  127. ' to create and release logical locks.
  128. '============================================================
  129. Option Explicit
  130. 'Declare a reference to the Logical Locks object.
  131. Private LogLock As LogicalLock
  132. 'Descriptions for "Exclusive" and "Shareable" locks.
  133. Private LockTypeDesc(1) As String
  134. Private Sub LockBtn_click()
  135.     Dim Handle As Long
  136.     'Lock Name should not be blank.
  137.     If (Trim(LockName.Text) = "") Then
  138.         MsgBox "You must specify a Lock Name", vbExclamation, "Missing Lock Name"
  139.         Exit Sub
  140.     End If
  141.     'Acquire the lock (if possible) and return a handle to it.
  142.     Handle = LogLock.AcquireLock(Trim(LockName.Text), IIf(LockType(0).Value = True, Exclusive, Shareable))
  143.     If Handle <> 0 Then
  144.         MsgBox "Lock Successfully Acquired", vbInformation, "Lock Acquired"
  145.     Else  'If Handle is zero, then lock was not acquired.
  146.         MsgBox "Lock could not be acquired", vbExclamation, "Lock Unsuccessful"
  147.     End If
  148.     UpdateLockList
  149. End Sub
  150. Private Sub RefreshBtn_Click()
  151.     'Update the list of locks held by this station.
  152.     UpdateLockList
  153. End Sub
  154. Private Sub UnlockBtn_Click()
  155.     Dim Res As Boolean
  156.     Dim Hdl As Long
  157.     If (LockList.ListCount = 0) Then
  158.         MsgBox "You are not currently holding any locks.", vbInformation, "No Locks"
  159.         Exit Sub
  160.     End If
  161.     If (LockList.ListIndex = -1) Then
  162.         MsgBox "You must select a lock to release.", vbInformation, "No Lock Selected"
  163.         Exit Sub
  164.     End If
  165.     Hdl = LockList.ItemData(LockList.ListIndex)
  166.     'Release the lock specified by the handle (Hdl).
  167.     Res = LogLock.ReleaseLock(Hdl)
  168.     'If ReleaseLock returns True, then lock was successfully released.
  169.     If (Res = True) Then
  170.         MsgBox "Lock Released", vbInformation, "Lock Released"
  171.     Else
  172.         MsgBox "Lock was not released.", vbExclamation, "Lock Not Released"
  173.     End If
  174.     UpdateLockList
  175. End Sub
  176. Private Sub UpdateLockList()
  177.     Dim LockName As String
  178.     Dim LockUser As String
  179.     Dim LockType As Integer
  180.     Dim LockHndl As Long
  181.     Dim User As String
  182.     Dim Res As Boolean
  183.     'Enumerate the locks held by this station.
  184.     'Add them to a list box showing all the
  185.     'properties of a logical lock:
  186.     'Name, Owner, Type, and Handle.
  187.     Screen.MousePointer = vbHourglass
  188.     User = LogLock.UserName
  189.     LockHndl = 0&
  190.     Res = LogLock.EnumerateLocks(LockHndl, User)
  191.     LockList.Clear
  192.     'EnumerateLocks returns True as long as another lock
  193.     'was found for the specified user.
  194.     Do While (Res = True)
  195.         If (LogLock.GetLockInfo(LockHndl, LockName, LockUser, LockType) = True) Then
  196.             LockList.AddItem Format(LockHndl) & vbTab & LockName & vbTab & LockUser & vbTab & LockTypeDesc(LockType)
  197.             LockList.ItemData(LockList.NewIndex) = LockHndl
  198.         End If
  199.         
  200.         Res = LogLock.EnumerateLocks(LockHndl, User)
  201.     Loop
  202.     If (LockList.ListCount > 0) Then LockList.ListIndex = 0
  203.     Screen.MousePointer = vbDefault
  204. End Sub
  205. Private Sub CloseBtn_Click()
  206.     Unload Me
  207. End Sub
  208. Private Sub Form_Load()
  209.     Dim Row As Integer
  210.     Dim Stops(3) As Long
  211.     Dim Res As Long
  212.     'Instantiate a new logical lock object.
  213.     Set LogLock = New LogicalLock
  214.     'Set the database directory path.
  215.     LogLock.DatabaseDir = App.Path
  216.     'Now start the logical lock server.
  217.     LogLock.InitializeLocks "loglock.mdb"
  218.     'Set up columns in the logical lock list box.
  219.     Stops(0) = 40
  220.     Stops(1) = 160
  221.     Stops(2) = 220
  222.     Res = SendMessage(LockList.hwnd, LB_SETTABSTOPS, 3&, Stops(0))
  223.     'Initialize lock type descriptions.
  224.     LockTypeDesc(0) = "Exclusive"
  225.     LockTypeDesc(1) = "Shareable"
  226. End Sub
  227. Private Sub Form_Unload(Cancel As Integer)
  228.     'Before closing the application completely,
  229.     'shut down the logical lock server and
  230.     'destroy its reference.
  231.     LogLock.ShutdownLocks
  232.     Set LogLock = Nothing
  233. End Sub
  234.